﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bll
{
    public class functionControl
    {
        String _check = "";
        checkString cs = new checkString();

        public String[] checkAddingTimeSheet(String _date, String _hours, String _descr)
        {
            String[] _msg = new String[5];

            //control Date
            Int32 _today = Int32.Parse(DateTime.Today.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture));
            Int32 _selectedDate = Int32.Parse(Convert.ToDateTime(_date).ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture));
            Int32 _thisYear = Int32.Parse(DateTime.Today.ToString("yyyy", System.Globalization.CultureInfo.InvariantCulture));
            Int32 _selectedYear = Int32.Parse(Convert.ToDateTime(_date).ToString("yyyy", System.Globalization.CultureInfo.InvariantCulture));
            if (_today < _selectedDate)
            {
                _msg[0] = "fail";
                _msg[2] = "Please don't select a date in the future!";
            }
            else if(_thisYear != _selectedYear)
            {
                _msg[0] = "fail";
                _msg[2] = "Please select a date this year!";
            }

            //control Hours
            _check = cs.checkIt(_hours, "hours");
            if (_check != "")
                {
                    _msg[0] = "fail";
                    _msg[3] = _check;
                }

            //control Description
            if (_descr == "" || _descr == " ")
            {
                _msg[0] = "fail";
                _msg[4] = "Please write a description into the provided textbox!";
            }

            return _msg;
        
        }//checkAddingTimeSheet()


        /// <summary>
        /// Checks the whole imput of a form and writes an error Text
        /// </summary>
        /// <returns> A boolean whether the imput is passed on the bll/db  </returns>
        public String[] checkNewEmployeeInput(String _name, String _email, String _hourlyRate, String _password)
        {
            checkString cs = new checkString();
            String[] _msg = new String[6];

            //control Name
            _check = cs.checkIt(_name, "name");
            if (_check != "")
            {
                _msg[0] = "fail";
                _msg[2] = _check;
            }

            //control Email
            _check = cs.checkIt(_email, "email");
            if (_check != "")
            {
                _msg[0] = "fail";
                _msg[3] = _check;
            }

            //control Hourly rate
            _check = cs.checkIt(_hourlyRate, "hourlyRate");
            if (_check != "")
                {
                    _msg[0] = "fail";
                    _msg[4] = _check;
                }

            //control Password
            _check = cs.checkIt(_password, "password");
            if (_check != "")
            {
                _msg[0] = "fail";
                _msg[5] = _check;
            }

            return _msg;
        }//checkNewEmployeeInput()
    }
}
